import axios from 'axios'
import NProgress from 'nprogress'
// 引入nprogress样式文件
import'nprogress/nprogress.css'

const request = axios.create({
    timeout:5000
})
NProgress.configure({ easing: 'ease', speed: 500, showSpinner: false })
request.interceptors.request.use(config=>{
    NProgress.start()
    config.headers.token = window.sessionStorage.getItem('token')||''
    return config
},error=>{
    return Promise.reject(error)
})

request.interceptors.response.use(res=>{
    NProgress.done()
    return res
},error=>{
    NProgress.done()
    return Promise.reject(error)
})

export default request